package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 分页查询菜品
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 菜品停售起售
     * @param dish
     */
    @Update("update dish set status = #{status}, update_time = #{updateTime}, update_user = #{updateUser} where id = #{id}")
    @AutoFill(OperationType.UPDATE)
    void status(Dish dish);

    /**
     * 删除菜品
     * @param dish
     */
    @Update("update dish set is_deleted = 1 where id = #{id}")
    @AutoFill(OperationType.UPDATE)
    void delDish(Dish dish);

    /**
     * 根据id查询菜品
     * @param id
     * @return
     */
    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    /**
     * 新增菜品
     * @param dish
     */
//    @Insert("insert into dish ( name, category_id, price, image, description, create_time, update_time, create_user, update_user) VALUES " +
//            "(#{name},#{categoryId},#{price},#{image},#{description},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @AutoFill(OperationType.INSERT)
    void save(Dish dish);

    /**
     * 修改菜品
     * @param dish
     */
    @Update("update dish set name = #{name}, category_id = #{categoryId}, price = #{price}, image = #{image}, description = #{description}," +
            "update_time = #{updateTime}, update_user = #{updateUser} where id = #{id}")
    @AutoFill(OperationType.UPDATE)
    void updateDish(Dish dish);

    /**
     * 根据分类查询菜品
     * @param categoryId
     * @return
     */
    @Select("select * from dish where category_id = #{categoryId} and is_deleted = 0")
    List<DishVO> getByCategoryId(Long categoryId);

    /**
     * 根据分类id查询菜品
     * @param categoryId
     */
    List<DishVO> list(Long categoryId);

    /**
     * 查询菜品总览
     * @param enable
     * @return
     */
    Integer getDishStatus(Integer enable);
}
